#include<stdio.h>
#include<stdlib.h>
void bhdy(int s,int b);
void prt();
int a[4],flag,count;
int main()
{
    int b1,b2,i,j,k=0,p,c;
    printf("Game guess your number in mind is # # # #.\n");
    for(i=1;i<10&&k<4;i++) 
    {
        printf("No.%d:your number may be:%d%d%d%d\n",++count,i,i,i,i);
        printf("How many digits have bad correctly guessed:");
        scanf("%d",&p); 
        for(j=0;j<p;j++)
            a[k+j]=i;
            k+=p; 
    }
    if(k<4) 
    for(j=k;j<4;j++)
        a[j]=0;
    i=0;
    printf("No.%d:your number may be:%d%d%d%d\n",++count,a[0],a[1],a[2],a[3]);
    printf("How many are in exact positions:");
    scanf("%d",&b1); 
    if(b1==4){prt();exit(0);} 
    for(flag=1,j=0;j<3&&flag;j++) 
        for(k=j+1;k<4&&flag;k++)
            if(a[j]!=a[k])
            {
                c=a[j];a[j]=a[k];a[k]=c; 
                printf("No.%d:Your number may be: %d%d%d%d\n",++count,a[0],a[1],a[2],a[3]);
                printf("How many are in exact positins:");
                scanf("%d",&b2);
                if(b2==4){prt();flag=0;} 
                else if(b2-b1==2)bhdy(j,k); 
                else if(b2-b1==-2) 
                {
                    c=a[j];a[j]=a[k];a[k]=c;
                    bhdy(j,k);
                }
                else if(b2<=b1)
                {
                    c=a[j];a[j]=a[k];a[k]=c; 
                }
                else b1=b2; 
            }
            if(flag) printf("You input error!\n"); 
}
void prt() 
{
printf("Now your number must be %d%d%d%d.\n",a[0],a[1],a[2],a[3]);
printf("Game Over\n");
}
void bhdy(int s,int b)
{
    int i,c=0,d[2];
    for(i=0;i<4;i++) 
        if(i!=s&&i!=b) d[c++]=i;
    i=a[d[1]];a[d[1]]=a[d[0]]; a[d[0]]=i;
    prt(); 
    flag=0;
}